/*
 * @Description: 连接mysql
 * @Author: lihk
 * @Date: 2024-09-25 14:06:11
 */
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (config: ConfigService) => ({
        type: 'mysql',
        host: config.get('DB_HOST'),
        port: config.get('DB_PORT'),
        username: config.get('DB_USERNAME'),
        password: config.get('DB_PASSWORD'),
        database: config.get('DB_DATABASE'),
        // entities: ["src/**/entities/*.entity.ts"], // 匹配所有 .entity 文件，
        autoLoadEntities: true, // 自动加载实体
        synchronize: true, //在开发环境中使用，生产环境不要使用
      }),
      inject: [ConfigService],
    }),
  ],
})
export class DatabaseModule {}